<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/6 0006
 * Time: 下午 3:31
 */
namespace app\common\model;

use app\lib\exception\ParameterException;
use think\Model;

class User extends Model{
    // 定义时间戳字段名
    protected $createTime = 'createDate';
    protected $updateTime = 'updateDate';
    protected $autoWriteTimestamp = 'datetime';
    public static function getByOpenID($openid){
        $user = self::where('openid','=',$openid)->find();
        return $user;
    }
    public static function getopenId($userId){
        $user = self::get($userId);
        if($user && $user->openId){
            return $user->openId;
        }else{
            throw new ParameterException([
                'msg' => '用户异常'
            ]);
        }
    }
}